import 'package:flutter/material.dart';
import 'package:jd_shopping/pages/ProductDetaileTabBarView/productDetaileTabBarView.dart';
import 'package:jd_shopping/pages/ProductDetaileTabBarView/productTabBarView.dart';
import 'package:jd_shopping/pages/ProductDetaileTabBarView/productEvaluationTabBarView.dart';
import 'package:jd_shopping/services/ScreenAdaper.dart';
import 'package:jd_shopping/pages/Coustom/JdButton.dart';
import 'package:jd_shopping/RequestMethod/httpRequestMtehod.dart';
import 'package:jd_shopping/Model/ProductDetaileModel.dart';
import 'package:jd_shopping/pages/Tools/EventBus.dart';



class ProductDetaile extends StatefulWidget {
   final Map arguments;
  ProductDetaile({Key key, this.arguments});
  @override
  _ProductDetaileState createState() => _ProductDetaileState();
}
class _ProductDetaileState extends State<ProductDetaile> with AutomaticKeepAliveClientMixin {
   final Map arguments;
  _ProductDetaileState({Key key, this.arguments});
  ProductDetaileItemModel _productDetaileItemModel ;
  
  @override
  bool get wantKeepAlive => true;

 @override
  void initState() {
     String sId =  '${widget.arguments['sId']}';
    HttpRequestMethod.getProductDetaileData(sId).then((response){
       var focusList = ProductDetaileModel.fromJson(response.data);
       setState(() {
           this._productDetaileItemModel = focusList.result;
           print('this._productDetaileItemModel----->${ this._productDetaileItemModel}');
        });
     });
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenAdaper.init(context);
    return DefaultTabController(
       length: 3,
       child:Scaffold(
         appBar: AppBar(
           title:Container(
             width: ScreenAdaper.getScreenWidth()-100,
             child:TabBar(
              isScrollable: false,
             indicatorColor:Colors.red,
             indicatorSize:TabBarIndicatorSize.label,
             tabs:[
               Tab(text:'商品'),
               Tab(text:'详情'),
               Tab(text:'评价'),
              ]
             ),
           ),
           actions: <Widget>[
              IconButton(
              icon: Icon(Icons.more_horiz),
              onPressed: (){
                showMenu(
                    context:context,
                    position:RelativeRect.fromLTRB(ScreenAdaper.width(600), 76, 10, 0),
                    items: [
                        PopupMenuItem(
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.home),
                              Text("首页")
                            ],
                          ),
                        ),
                        PopupMenuItem(
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.search),
                              Text("搜索")
                            ],
                          ),
                        )
                    ]
                );
              },
            )
           ],
         ),
         body: Stack(
           children: <Widget>[
              TabBarView(
                 children: [
                    ProductTabBarView(productDetaileItemModel:this._productDetaileItemModel),
                    ProductDetaileTabBarView(),
                    ProductEvaluationTabBarView()
                   ],
                  physics: NeverScrollableScrollPhysics(),
               ),
               Positioned(
                width: ScreenAdaper.getScreenWidth() ,
                 height: ScreenAdaper.height(134),
                 bottom: 0,
                 child:Container(
                   decoration: BoxDecoration(
                      border: Border(
                    top: BorderSide(
                      color: Colors.black26,
                      width: 1
                      )
                     ),
                     color: Colors.white
                   ),
                   child:Row(
                   children: <Widget>[
                     InkWell(
                       child: Container(
                        padding: EdgeInsets.all(ScreenAdaper.height(20)),
                        child: Column(
                        children: <Widget>[
                        Icon(Icons.shopping_cart),
                        Text("购物车")
                       ],
                      ),
                   ),
                   onTap:(){
                      Navigator.pushNamed(context, '/cart');
                   },
                   ),
                    Expanded(
                      flex: 1,
                      child: JdButton(
                        color:Color.fromRGBO(253, 1, 0, 0.9),
                        text: "加入购物车",
                        cb: (){
                         eventBus.fire(new ProductContentEvent('加入购物车'));
                        },
                      ),
                    ),

                    Expanded(
                      flex: 1,
                      child: JdButton(
                        color: Color.fromRGBO(255, 165, 0, 0.9),
                        text: "立即购买",
                        cb: (){
                          eventBus.fire(new ProductContentEvent('立即购买'));
                        },
                      ),
                    )
                   ],
                   ),
                   ),
                 )
           ],
         )
       )
    );
  }
}